package com.woniuxy.stage3demo.service.gy.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.gy.OverdueBean;
import com.woniuxy.stage3demo.bean.gy.ResultMesDemo;
import com.woniuxy.stage3demo.bean.gy.UserDemo;
import com.woniuxy.stage3demo.mapper.gy.OverdueMapper;
import com.woniuxy.stage3demo.service.gy.OverdueService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**关于逾期表的操作
 * @author ：苟杨
 * @description：TODO
 * @date ：2020/12/9 16:39
 */
@Transactional(readOnly = true)
@Service
public class OverdueServiceImpl implements OverdueService {
    @Resource
    private OverdueMapper overdueMapper;
    //分页查询
    @Override
    public PageInfo<OverdueBean> findAll(int pageNum, int pageSize, UserDemo userDemo) {
        return PageHelper.startPage(pageNum,pageSize).doSelectPageInfo(()->overdueMapper.findAll(userDemo));
    }

    //分页查询
    @Override
    public PageInfo<OverdueBean> findAllReduce(int pageNum, int pageSize, UserDemo userDemo) {
        return PageHelper.startPage(pageNum,pageSize).doSelectPageInfo(()->overdueMapper.findAllReduce(userDemo));
    }
    //查询每个月的逾期总数
    @Override
    public int findCountMonth() {
        return overdueMapper.findCountMonth();
    }
    //查询每年的逾期
    @Override
    public int findCountYear() {
        return overdueMapper.findCountYear();
    }
    //查询每个月的逾期金额和利息
    @Override
    public List<ResultMesDemo> findMonthMoney() {
        return overdueMapper.findMonthMoney();
    }
    //查询每年的金额和利息
    @Override
    public List<ResultMesDemo> findYearMoney() {
        return overdueMapper.findYearMoney();
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public int updateLateCharge(int id,int lateCharge) {
        return overdueMapper.updateLateCharge(id,lateCharge);
    }
}
